import pyodbc
from datetime import datetime
import requests
def task():
    print("任务执行中...")


def chekcin(num):
    connection_string = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=172.16.106.40,1433;DATABASE=zkprd;UID=sa;PWD=INIT@1234zk"
    conn = pyodbc.connect(connection_string)
    # 创建一个游标对象
    cursor = conn.cursor()
    # 获取当前时间
    current_time = datetime.now()
    # 格式化时间
    formatted_time = current_time.strftime('%Y-%m-%d')
    # 执行 SQL 查询
    sql_query = "SELECT TOP 10 FORMAT(checktime, 'yyyy-MM-dd HH:mm:ss') AS FormattedDate,checktype from checkinout a INNER JOIN userinfo b on a.userid=b.userid and badgenumber='31000072' and checktime>'{}' ORDER BY checktime desc".format(formatted_time)
    print(sql_query)
    cursor.execute(sql_query)
    # 获取查询结果
    results = cursor.fetchall()
    # 打印查询结果
    ret = []
    for row in results:
        rowStr=", ".join(map(str, row))
        ret.append(rowStr)
        print(rowStr)

    title="打卡次数：{}".format(len(ret))
    if(len(ret)<num):
        title="漏{}".format((num-len(ret)))

    # 关闭连接
    conn.close()
    # 将数组转换为逗号分隔的字符串，作为text参数的值
    text_param = ' '.join(ret)
    # 目标URL
    url = "https://iyuu.cn/IYUU3985Tf505ccdf744edcfc71f2a7c3dea7190c3b687f51.send"
    # 发送POST请求
    # 发送GET请求
    response_get = requests.get(url, params={'text': title})
    print("GET Response:", response_get.text)
    response_post = requests.post(url, data={'text': text_param})
    print("POST Response:", response_post.text)
